package org.iabako.client.ui.page.business.paymentrequest;

import org.iabako.client.config.page.PageConfigEnum;
import org.iabako.client.tools.IabakoAsyncCallback;
import org.iabako.client.ui.form.business.paymentrequest.PaymentRequestConfigForm;
import org.iabako.client.user.AuthenticateUserProvider;
import org.iabako.shared.entity.enumeration.IabakoPackage;
import org.iabako.shared.exception.IabakoActionForbiddenException;

/**
 * Created by jose on 15/01/15.
 */
public class PaymentRequestConfig extends PaymentRequestConfigForm {

    public PaymentRequestConfig() throws IabakoActionForbiddenException {
        super(PageConfigEnum.PaymentRequestConfiguration);

        IabakoPackage userPackage = AuthenticateUserProvider.getUser().getUserCredit().getIabakoPackage();
        if (!userPackage.isFree() && !userPackage.isEnterprise()) {
            throw new IabakoActionForbiddenException("payment_request_disable_for_starter_title", "payment_request_disable_for_starter_text", true);
        }

        paymentRequestServiceAsync.getByEnterprise(new IabakoAsyncCallback<org.iabako.shared.entity.business.PaymentRequestConfig>() {
            public void onSuccess(org.iabako.shared.entity.business.PaymentRequestConfig result) {
                setPaymentRequestConfig(result);
                super.onSuccess(result);
            }
        });
    }
}
